<template>
  <div class="mod-order-order">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter="getDataList(page)"
    >
      <el-form-item label="订单编号:" >
        <el-input
          v-model="dataForm.orderNumber"
          placeholder="订单编号"
          clearable
          style="width: 200px;"
        />
      </el-form-item>
      <el-form-item label="申请时间:">
        <el-date-picker
          v-model="dateRange"
          type="datetimerange"
          range-separator="至"
          value-format="YYYY-MM-DD HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item label="订单状态:">
        <el-select
          v-model="dataForm.status"
          clearable
          placeholder="请选择退款申请状态"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="getDataList()"
        >
          查询
        </el-button>
        <el-button @click="clearDatas()">
          清空
        </el-button>
      </el-form-item>
    </el-form>
    <div class="main">
      <div class="content">
        <div class="tit">
          <el-row style="width:100%">
            <el-col :span="6">
              <span class="item product">商品</span>
            </el-col>
            <el-col :span="4">
              <span class="item">退款金额/退款数量</span>
            </el-col>
            <el-col :span="3">
              <span class="item">状态</span>
            </el-col>
            <el-col :span="3">
              <span class="item">实付金额</span>
            </el-col>
            <el-col :span="3">
              <span class="item">支付方式</span>
            </el-col>
            <el-col :span="3">
              <span class="item">物流信息</span>
            </el-col>
            <el-col :span="2">
              <span class="item">操作</span>
            </el-col>
          </el-row>
        </div>
        <div
          v-for="order in dataList"
          :key="order.orderId"
          class="prod"
        >
          <div class="prod-tit">
            <span>订单编号：{{ order.orderNumber }}</span>
            <span>申请时间：{{ order.applyTime }}</span>
          </div>
          <div class="prod-cont">
            <el-row style="width:100%">
              <el-col :span="8">
                <div class="prod-item">
                  <div
                    class="items name"
                  > <!--                    v-for="orderItem in order.orderItems"
                    :key="orderItem.orderItemId"-->
                    <div class="prod-image">
                      <img
                        alt=""
                        :src="resourcesUrl + order.pic"
                        style="height:100px;width: 100px;"
                      >
                    </div>
                    <div class="prod-name">
                      <span>{{ order.prodName }}</span>
                      <span class="prod-info">{{ order.skuName }}</span>
                    </div>
                    <div class="prod-price">
                      <span>￥{{ order.refundAmount }}</span>
                      <span>×{{ order.goodsNum }}</span>
                    </div>
                  </div>
                </div>
              </el-col>

              <el-col
                :span="4"
                style="height: 100%;"
              >
                <div class="item">
                  <div>
                    <div>
                    <span v-if="order.refundSts === 1">待审核</span>
                    <span v-else-if="order.refundSts === 2">通过</span>
                    <span v-else-if="order.refundSts === 3">驳回</span>
                  </div>
                  </div>
                </div>
              </el-col>

              <el-col
                :span="3"
                style="height: 100%;"
              >
                <div class="item">
                  <div>
                    <span class="totalprice">￥{{ order.orderAmount }}</span>
                    <!--<span v-if="order.freightAmount">（含运费：￥{{ order.freightAmount }}）</span>-->
                    <span>共{{ order.prodCount }}件</span>
                  </div>
                </div>
              </el-col>
              <el-col
                :span="3"
                style="height: 100%;"
              >
                <div class="item">
                  <div>
                    <span v-if="order.payType === 1">微信支付</span>
                    <span v-else-if="order.payType === 2">支付宝</span>
                    <span v-else>手动代付</span>
                  </div>
                </div>
              </el-col>
              <el-col
                :span="3"
                style="height: 100%;"
              >
                <div class="item">
                 <div>
                  <span >快递公司:{{order.expressName}}</span><br>
                  <span>快递单号:{{order.expressNo}}</span>
                </div>
                </div>
              </el-col>
              <el-col
                :span="3"
                style="height: 100%;"
              >
                <div class="item">
                  <div class="operate">
                    <el-button
                      v-if="isAuth('order:refund:approval')"
                      type="text"
                      @click="openApproval(order)"
                    >
                      审批
                    </el-button>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
          <div class="remark">
            <div class="buyer-remark">
              <span>申请原因:{{ order.buyerMsg }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 空 -->
    <div
      v-if="!dataList.length"
      class="empty-tips"
    >
      暂无数据
    </div>
    <el-pagination
      :current-page="page.pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="page.pageSize"
      :total="page.total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
    />

    <!--审批-->
    <approval v-if="approvalVisible" ref="approvalRef" @refresh-data-list="getDataList" />

  </div>
</template>

<script setup>
import { isAuth } from "@/utils";
const resourcesUrl = import.meta.env.VITE_APP_RESOURCES_URL
import approval from "./components/approval.vue";

const dataList = ref([]);
const dataListLoading = ref(false);
const dataListSelections = ref([]);
const addOrUpdateVisible = ref(false);
const page = reactive({
  total: 0, // 总页数
  currentPage: 1, // 当前页数
  pageSize: 10, // 每页显示多少条
});
onMounted(() => {
  getDataList(page)
})

const options = [{
  value: 1,
  label: '待审核'
},
{
  value: 2,
  label: '同意'
},
{
  value: 3,
  label: '不同意'
}]

const dataForm = ref({})
const dateRange = ref([])

/**
 * 清除数据
 */
const clearDatas = () => {
  dataForm.value = {}
  dateRange.value = []
}

/**
 * 获取数据列表
 */
const getDataList = (pageParam, params, done) => {
  dataListLoading.value = true;
  http({
    url: http.adornUrl("/order/refund/page"),
    method: "get",
    params: http.adornParams(
      Object.assign(
        {
          current: pageParam == null ? page.currentPage : pageParam.currentPage,
          size: pageParam == null ? page.pageSize : pageParam.pageSize,
          orderNumber: dataForm.value.orderNumber,
          status: dataForm.value.status,
          startTime: dateRange.value === null ? null : dateRange.value[0], // 开始时间
          endTime: dateRange.value === null ? null : dateRange.value[1] // 结束时间
        },
        params
      )
    ),
  }).then(({ data }) => {
    dataList.value = data.records;
    page.total = data.total;
    dataListLoading.value = false;
    if (done) done();
  });
};

/**
 * 条件查询
 */
const onSearch = (params, done) => {
  getDataList(page, params, done);
};


const approvalVisible = ref(false);
const approvalRef = ref(null);
const openApproval = (row) => {
  approvalVisible.value = true;
  nextTick(() => {
    approvalRef.value?.init(row);
  });
};

</script>

<style lang="scss" scoped>
.mod-order-order {
  .tit {
    display: flex;
    height: 45px;
    align-items: center;
  }

  .tit {
    .item {
      padding: 0 10px;
      width: 10%;
      text-align: center;
    }

    .product {
      width: 25%;
    }
  }

  .prod-tit {
    padding: 10px;
    background: #f8f8f9;
    border-left: 1px solid #dddee1;
    border-top: 1px solid #dddee1;
    border-right: 1px solid #dddee1;

    span {
      margin-right: 15px;
    }
  }

  .prod-cont {
    display: flex;
    border-top: 1px solid #dddee1;
    border-bottom: 1px solid #dddee1;
    border-left: 1px solid #dddee1;
    color: #495060;

    .item {
      display: flex;
      display: -webkit-flex;
      align-items: center;
      justify-content: center;
      padding: 10px;
      border-right: 1px solid #dddee1;
      text-align: center;
      height: 100%;

      span {
        display: block;
      }
    }

    .prod-item {
      display: flex;
      flex-direction: column;
      border-right: 1px solid #dddee1;
    }

    .items.name {
      display: flex;
      position: relative;
      padding: 20px;
      border-bottom: 1px solid #dddee1;

      &:last-child {
        border-bottom: none;
      }
    }
  }

  .prod-name {
    width: 55%;
    text-align: left;

    .prod-info {
      display: block;
      color: #80848f;
      margin-top: 30px;
    }
  }

  .prod-price {
    position: absolute;
    right: 40px;
    text-align: right;

    span {
      display: block;
      margin-bottom: 10px;
    }
  }

  .prod-image {
    margin-right: 20px;
    width: 100px;
    height: 100px;

    img {
      width: 100px;
      height: 100px;
    }
  }

  .item {
    span {
      display: block;
      margin-bottom: 10px;
    }

    .operate {
      color: #2d8cf0;
    }

    .totalprice {
      color: #c00;
    }
  }

  .prod {
    .remark {
      width: 100%;
      height: 50px;
      line-height: 50px;
      background-color: #e8f7f6;
      border-left: 1px solid #dddee1;
      border-right: 1px solid #dddee1;
      border-bottom: 1px solid #dddee1;
      margin-bottom: 20px;
    }
  }

  .buyer-remark {
    padding: 0 20px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .empty-tips {
    display: block;
    width: 100%;
    text-align: center;
    margin: 50px 0;
    color: #999;
  }
}
</style>
